/**
 * Created by gaoyj on 2018/6/28.
 */
window.onload = function (ev) {
    topbar.hide();
};
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
if (month < 10) {
    month = "0" + month;
}
if (day < 10) {
    day = "0" + day;
}
var _start = myDate.getFullYear() + '-' + month + '-' + day + " 00:00:00";
var _end = myDate.getFullYear() + '-' + month + '-' + day + " 23:59:59";
$("#startTime").val(_start);
$("#endTime").val(_end);
laydate.render({
    elem: '#startTime',
    type: 'datetime',

});
laydate.render({
    elem: '#endTime' //指定元素
    , type: 'datetime',
});
$('#dataTable').bootstrapTable({
    url: '/CollectCardProfitDailyReportController/queryDailyReport',
    height: $(window).height() - 200,
    pageSize: 30,
    pagination: true,
    pageList: [30, 50, 100],
    clickToSelect: true,
    queryParams: queryParams,
    uniqueId: 'id',
    queryParamsType: '',
    sidePagination: 'server',
    responseHandler: function (res) {
        return {
            "total": res.length,
            "rows": res
        };
    },
    columns: [[
        {
            width: '3px',
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        },{field: 'productType', title: '运营商', width: 90, align: 'center',formatter:function (v, o) {
            var typeConvert = productTypeConvert(v);
            if(typeConvert){
                return typeConvert;
            }
            return "全部";
        }},
        {field: 'successTotal', title: '成功笔数', width: 90, align: 'center', sortable: true},
        {field: 'totalFace', title: '成功总面值', width: 90, align: 'center', sortable: true},
        {field: 'failTotal', title: '失败笔数', width: 90, align: 'center', sortable: true},
        {field: 'sales', title: '销卡价格', width: 90, align: 'center', sortable: true},
        {field: 'costs', title: '收卡价格', width: 90, align: 'center', sortable: true},
        // {field: 'salesFee', title: '销卡处理费用', width: 90, align: 'center', sortable: true},
        {field: 'chargeFee', title: '代充费用', width: 90, align: 'center', sortable: true},
        {field: 'averageChargeFee', title: '平均代充费用', width: 90, align: 'center', sortable: true,formatter:function(v,o){
            var total=o.successTotal+o.failTotal;
            if(total){
                return Math.round(o.chargeFee/total*100000)/100000;
            }
            return "-";
        }},
        {field: 'xianyuCommission', title: '闲鱼佣金', width: 90, align: 'center', sortable: true},
        {field: 'profit', title: '利润', width: 90, align: 'center', sortable: true},
        {field: 'profitRate', title: '利润率', width: 90, align: 'center', sortable: true,formatter:function (v, o) {

            return v+"%";
        }},
    ]]
});

$("#search").click(function () {
    var timeAdd = new Date($("#startTime").val());
    var timeEnd = new Date($("#endTime").val());
    if (timeAdd > timeEnd) {
        layer.msg("开始时间不能大于结束时间");
        return false;
    }
    $("#dataTable").bootstrapTable("refresh");
});

function queryParams(params) {
    return {
        size: params.pageSize,
        page: params.pageNumber,
        startTime: $("#startTime").val(),
        endTime: $("#endTime").val(),
        exkChannelPlat: $("#exkChannelPlat").val(),
    };
}